#pragma once

#include "../Common/QuitableThread.hpp"
#include "../Common/SafeQueue.hpp"
#include "../Common/LogItem.hpp"

#include <fstream>
#include <iostream>

namespace cybertron {
	class LogLocalWriter : public QuitableThread
	{
	public:
		LogLocalWriter(SafeQueue<LogItem> *input_queue) : _input_queue(input_queue), _enable_console(false), _enable_file(false), _last_flush_time(0) {};
		virtual ~LogLocalWriter() {
			if (_file.is_open()) {
				_file.close();
			}
		};

		int enable_console();
		int enable_file(const std::string &file_path);

	private:
		virtual void run_once();
		SafeQueue<LogItem> *_input_queue;
		bool _enable_console;
		bool _enable_file;
		std::ofstream _file;
		time_t _last_flush_time;
	};
}

